import { message } from 'antd';
import axios from 'axios';

interface ApiError {
  message: string;
  code: number;
}

interface ApiErrorResponse {
  response?: {
    data?: {
      message?: string;
    };
  };
  message: string;
}

export const handleApiError = (error: unknown) => {
  const err = error as ApiErrorResponse;
  const errorMessage = err.response?.data?.message || err.message;
  message.error(errorMessage);
};

export const downloadFile = (data: Blob, filename: string) => {
  const url = window.URL.createObjectURL(data);
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', filename);
  document.body.appendChild(link);
  link.click();
  link.remove();
  window.URL.revokeObjectURL(url);
}; 